package com.topinfo.etl.controller;

import com.jpx.component.model.service.IModelService;
import com.topinfo.component.base.bean.JsonResponse;
import com.topinfo.component.base.controller.AbstractModelController;
import com.topinfo.etl.bean.EtlDatasourceCfg;
import com.topinfo.etl.bean.EtlSynctableCfg;
import com.topinfo.etl.service.EtlDatasourceCfgService;
import com.topinfo.etl.service.EtlSynctableCfgService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 同步表配置信息
 */
@Controller
@RequestMapping("/etl/etlsynctablecfg")
public class EtlSynctableCfgController extends AbstractModelController<EtlSynctableCfg> {

    @Resource
    private EtlSynctableCfgService etlSynctableCfgService;

    @Override
    protected IModelService<EtlSynctableCfg> getModelService() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        this.etlSynctableCfgService.setRequest(request);
        return this.etlSynctableCfgService;

    }

    @RequestMapping({"/generate"})
    @ResponseBody
    public JsonResponse generate(String rows, String sourceDbId, String targetDbId, String savePath) {
        return etlSynctableCfgService.generate(rows, sourceDbId, targetDbId, savePath);
    }

    @RequestMapping({"/tableListSearch"})
    @ResponseBody
    public JsonResponse tableListSearch(String sourceId) {
        return etlSynctableCfgService.tableListSearch(sourceId);
    }
}
